//
//  YXTUserUtil.m
//  daxue
//
//  Created by hanjun on 16/5/9.
//  Copyright © 2016年 cn.yunxuetang. All rights reserved.
//

#import "YXTUserUtil.h"

@implementation YXTUserUtil

+ (NSString *)stringWithFilePath
{
//    if ([@"debug" isEqualToString:kProjectMode]) {
//        return [APP_DOC_DIR stringByAppendingPathComponent:@"debugaccount.data"];
//    }
    return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"account.data"];
}

/**
 *  存储账号信息
 *
 *  @param account 需要存储的账号
 */
+ (void)save:(YXTUserInfo *)account {
    // 归档
    BOOL b = [NSKeyedArchiver archiveRootObject:account toFile:[self stringWithFilePath]];
    NSLog(@"存储账号信息:%@",b?@"yes":@"no");
}

/**
 *  返回存储的账号信息
 */
+ (YXTUserInfo *)account {
    @try {
        YXTUserInfo *account = [NSKeyedUnarchiver unarchiveObjectWithFile:[self stringWithFilePath]];
        return account;
    } @catch (NSException *exception) {
        return nil;
    }
}

@end
